///////////// 这个是加文字水印的
package com.img;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.FileInputStream;
import java.io.FileOutputStream;

import javax.imageio.ImageIO;
import javax.swing.JFrame;

import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageDecoder;
import com.sun.image.codec.jpeg.JPEGImageEncoder;

public class ImgBean {
public static void main(String[] args) {
try {
// 读取模板图片内容

JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(new FileInputStream("c:1.JPG"));
BufferedImage image = decoder.decodeAsBufferedImage();
Graphics g = image.getGraphics();

//BufferedImage image = ImageIO.read(new FileInputStream("c:1.JPG"));
//Graphics2D g = image.createGraphics();// 得到图形上下文
g.setColor(Color.BLACK); // 设置画笔颜色
// 设置字体
Font font=new Font("大标宋", Font.LAYOUT_LEFT_TO_RIGHT, 14);
g.setFont(font);

g.drawString("016478", 270,282);// 写入签名
g.dispose();

FileOutputStream out = new FileOutputStream("c:test1.jpg");
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(image);
out.close();
System.out.println("ok");
} catch (Exception e) {
e.printStackTrace();
}

}
}


